package com.shizhanzhe.zxbapp.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

import com.shizhanzhe.zxbapp.bean.UserBean;
import com.shizhanzhe.zxbapp.url.Path;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

/**
 * Created by zz9527 on 2017/6/23.
 */

public class InstallReceiver extends BroadcastReceiver {
    public InstallReceiver() {

    }

    @Override
    public void onReceive(final Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
            String packageName = intent.getData().getSchemeSpecificPart();
            OkHttpDownloadJsonUtil.downloadJson(context, Path.APPINSTALL(UserBean.uid,packageName,Util.androidId(context)), new OkHttpDownloadJsonUtil.onOkHttpDownloadListener() {
                @Override
                public void onsendJson(String json) {
                    try {
                        JSONObject jsonObject = new JSONObject(json);
                        Toast.makeText(context,                         jsonObject.optString("info")
                                , Toast.LENGTH_LONG).show();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
}
